import * as apiService from '@/services/api';

/**
 * 获取佣金配置列表
 * @param params
 * @returns {Promise<*>}
 *
 */

const getCommissionList = params => apiService.post(api.COMMISSION_LIST, params);
/**
 * 获取佣金配置列表(下拉列表）
 * @returns {Promise<*>}
 *
 */

const getCommissionSelect = () => apiService.post(api.COMMISSION_SELECT);
/**
 * 获取佣金审核人列表
 * @param params
 * @returns {Promise<*>}
 *
 */

const getCommissionAuditor = params => apiService.post(api.COMMISSION_AUDITOR, params);
/**
 * 返佣初审
 * @param params
 * @returns {Promise<*>}
 *
 */

const updateApproveFirst = params => apiService.post(api.COMMISSION_APPROVE_FIRST, params);
/**
 * 返佣二审
 * @param params
 * @returns {Promise<*>}
 *
 */

const updateApproveSecond = params => apiService.post(api.COMMISSION_APPROVE_SECOND, params);
/**
 * 获取佣金配置详情
 * @param params
 * @returns {Promise<*>}
 *
 */

const getCommissionDetail = params => apiService.post(api.COMMISSION_DETAIL, params);
/**
 * 获取下次代理佣金配置详情
 * @param params
 * @returns {Promise<*>}
 *
 */

const getSubCommissionConfigs = params => apiService.post(api.COMMISSION_SUB_CONFIGS_GET, params);
const getProxyCommissionConfigs = params => apiService.post(api.COMMISSION_PROXY_GET, params);
const getProxyCommissionDetail = params => apiService.post(api.COMMISSION_SUB_GET, params);

/**
 * 获取下次代理佣金配置详情
 * @param params
 * @returns {Promise<*>}
 *
 */

const getSubCommissionProxy = params => apiService.post(api.COMMISSION_SUB_PROXY_GET, params);
/**
 * 更新下次代理佣金配置详情
 * @param params
 * @returns {Promise<*>}
 *
 */

const updateSubCommissionConfigs = params => apiService.post(api.COMMISSION_SUB_CONFIGS_UPDATE, params);
/**
 * 获取结算分摊设置
 * @param params
 * @returns {Promise<*>}
 *
 */

const getSettlementApportion = params => apiService.post(api.COMMISSION_SETTLEMENT_CONFIGS, params);

/**
 * 获取下级代理佣金详情
 * @param {number} settleId 结算ID
 * @param {number} parentId 上级代理ID
 * @returns {*} Promise
 *
 */
export function getCommissionSubProxy({
  settleId,
  parentId,
}) {
  return apiService.post('/gl/comm/manage/commission/sub/proxy', {
    settleId,
    parentId,
  });
}

/**
 * 导出下级代理佣金详情
 * @param {number} settleId 结算ID
 * @param {number} commMode 佣金模式
 * @returns {*} Promise
 *
 */
export function getCommissionExportSubProxy({
  settleId,
  commMode,
}) {
  return apiService.post('/gl/comm/manage/commission/export/sub/proxy', {
    settleId,
    commMode,
  });
}
/**
 * 新增修改结算分摊
 * @param params
 * @returns {Promise<*>}
 *
 */

const editSettlementApportion = params => apiService.post(api.COMMISSION_SETTLEMENT_APPORTION, params);
/**
 * 获取平台费分摊
 * /gl/comm/manage/detail/platform
 * @param params
 * @returns {Promise<*>}
 *
 */

const getFundFeeApportion = params => apiService.post(api.COMMISSION_FUND_FEE_APPORTION_GET, params);
/**
 * 查询上分手续费
 * /gl/comm/manage/detail/platform
 * @param params
 * @returns {Promise<*>}
 *
 */

const getUpAmountsApportion = params => apiService.post(api.COMMISSION_UP_AMOUNTS_APPORTION_GET, params);
/**
 * 新增修改上分手续费
 * @param params
 * @returns {Promise<*>}
 *
 */

const editUpAmountsApportion = params => apiService.post(api.COMMISSION_UP_AMOUNTS_APPORTION_EDIT, params);
/**
 * 新增修改平台费分摊
 * @param params
 * @returns {Promise<*>}
 *
 */

const editFundFeeApportion = params => apiService.post(api.COMMISSION_FUND_FEE_APPORTION_EDIT, params);
/**
 * 存提款手续费详细
 * @param params
 * @returns {Promise<*>}
 *
 */

const getFundFeeDetail = params => apiService.post(api.COMMISSION_FUND_FEE_DETAIL_GET, params);
/**
 * 上下分手续费明细
 * @param params
 * @returns {Promise<*>}
 *
 */

const getUpAmountFeeDetail = params => apiService.post(api.COMMISSION_UP_AMOUNTS_APPORTION_DETAIL, params);
/**
 * 新增修改返佣设置
 * @param params
 * @returns {Promise<*>}
 *
 */

const editCommissionConfigs = params => apiService.post(api.COMMISSION_CONFIGS, params);
/**
 * 新增修改佣金配置
 * @param params
 * @returns {Promise<*>}
 *
 */

const editCommission = (params) => {
  const {
    id,
    name,
    status,
  } = params;
  if (_.isUndefined(id)) {
    return apiService.post(api.COMMISSION_ADD, {
      name,
      status,
    });
  }
  return apiService.post(api.COMMISSION_EDIT, {
    id,
    name,
    status,
  });
};
/**
 * 删除佣金配置
 * @param params
 * @returns {Promise<*>}
 *
 */

export const deleteCommissionItem = ({
  id,
} = {}) => apiService.post(api.COMMISSION_DELETE, {
  id,
});

/**
 * 获取现金网佣金配置列表
 * @returns {*} Promise
 *
 */
export function getCommissionCaseList() {
  return apiService.post('/gl/comm/manage/list/rule/cash');
}

/**
 * 获取现金网方案列表（下拉选择使用
 * @returns {*} Promise
 *
 */
export function getCommissionCaseSelectList() {
  return apiService.post('/gl/comm/manage/list/rule/cash/name');
}

/**
 * 获取现金网会员返佣配置
 * @param {number} id 方案ID
 * @returns {*} Promise
 *
 */
export function getCommissionCaseDetails({
  id,
} = {}) {
  return apiService.post('/gl/comm/manage/detail/commission', {
    id,
  });
}

/**
 * 新增现金网佣金配置详情/更新现金网方案
 * @param {number} id 方案ID
 * @param {string} name 方案名称
 * @param {number} status 状态：0正常，1禁用
 * @param {array} commList
 * {
 *   profit 总输值
 *   userCount 有效会员数
 *   commission 返佣比例（n）%
 *   commissionLimit 最大返佣额（元）
 * }
 * @returns {*} Promise
 *
 */
export const updateCommissionCaseDetails = ({
  name,
  status = 0,
  id,
  commList,
} = {}) => {
  if (id) {
    return apiService.post('/gl/comm/manage/set/rule/cash', {
      id,
      name,
      status,
      commList,
    });
  }
  return apiService.post('/gl/comm/manage/add/rule/cash', {
    name,
    status,
    commList,
  });
};

/**
 * 删除现金网佣金配置
 * @param {number} id 方案ID
 * @returns {*} Promise
 *
 */
export function deleteCommissionCaseItem({
  id,
} = {}) {
  return apiService.post('/gl/comm/manage/del/rule/cash', {
    id,
  });
}


/**
 * 生成上个月佣金报表
 * @param params
 * @returns {Promise<*>}
 *
 */

const generateCommissionList = params => apiService.post(api.COMMISSION_GENERATE_LIST, params);
/**
 * 获取佣金审核列表
 * @param params
 * @returns {Promise<*>}
 *
 */

const getCommissionAudits = params => apiService.post(api.COMMISSION_AUDITS, params);
/**
 * 导出佣金审核列表
 * @param params
 * @returns {Promise<*>}
 *
 */

const getCommissionAuditsExport = params => apiService.post(api.COMMISSION_AUDITS_EXPORT, params);
/**
 * 查询审核完毕的代理返佣列表
 * @param params
 * @returns {Promise<*>}
 *
 */

const getCommissionFinishList = params => apiService.post(api.COMMISSION_FINISH_LIST, params);
/**
 * 代理佣金批量审核
 * @param params
 * @returns {Promise<*>}
 *
 */

const updateMultipleAuditStatus = params => apiService.post(api.COMMISSION_AUDITS_UPDATE_MULTIPLE, params);
/**
 * 代理佣金单个审核
 * @param params
 * @returns {Promise<*>}
 *
 */

const updateAuditStatus = params => apiService.post(api.COMMISSION_AUDITS_UPDATE, params);
/**
 * 获取佣金结算记录
 * @param params
 * @returns {Promise<*>}
 *
 */

const getCommissionLogs = params => apiService.post(api.COMMISSION_LOGS, params);
/**
 * 佣金手工调整
 * @param params
 * @returns {Promise<*>}
 *
 */

const adjustCommission = params => apiService.post(api.COMMISSION_ADJUST, params);

/**
 * 查询游戏平台佣金
 * @param params
 * @returns {Promise<*>}
 *
 */

const gameCommission = params => apiService.post(api.COMMISSION_GAME_GET, params);
/**
 * 查询成本分摊
 * @param params
 * @returns {Promise<*>}
 *
 */

const costCommission = params => apiService.post(api.COMMISSION_COST_GET, params);

// 查询代充返利方案列表
const agentRechargeRebatePlansList = params => apiService.post(api.AGENT_RECHARGE_REBATE_PLANS_LIST, params);
// 代理返充方案修改
const agentRechargeRebatePlansSave = params => apiService.post(api.AGENT_RECHARGE_REBATE_PLAN_SAVE, params);
// 删除代理返充方案
const deleteAgentRechargeRebatePlans = ({
  userId,
  ruleId,
} = {}) => apiService.post(api.AGENT_RECHARGE_REBATE_PLAN_DELETE, {
  userId,
  ruleId,
});
// 修改

export {
  agentRechargeRebatePlansList,
  agentRechargeRebatePlansSave,
  deleteAgentRechargeRebatePlans,

  getCommissionList,
  getCommissionDetail,
  editCommission,
  editSettlementApportion,
  editFundFeeApportion,
  getFundFeeDetail,
  getUpAmountFeeDetail,
  editCommissionConfigs,
  generateCommissionList,
  getCommissionAudits,
  getCommissionAuditsExport,
  getCommissionLogs,
  updateMultipleAuditStatus,
  updateAuditStatus,
  getFundFeeApportion,
  getUpAmountsApportion,
  editUpAmountsApportion,
  adjustCommission,
  getSettlementApportion,
  updateApproveFirst,
  updateApproveSecond,
  getCommissionSelect,
  getCommissionAuditor,
  getCommissionFinishList,
  getSubCommissionConfigs,
  getProxyCommissionConfigs,
  getProxyCommissionDetail,
  updateSubCommissionConfigs,
  getSubCommissionProxy,
  gameCommission,
  costCommission,
};
